const app = getApp();
import HttpRequst from '../../utils/httpRequst.js'
import API from '../../utils/config.js'


Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollViewH:0,
    page: 1,
    pagesize:10,
    state:0,
    scrollTop:0,
    isLoading: true,
    isEnding: false,
    info:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    wx.getSystemInfo({
      success: function (res1){
        const query = wx.createSelectorQuery()
        query.select('#J_sec-header-container').boundingClientRect();
        // query.select('#J_add-staff-btn').boundingClientRect();
        query.exec(function (res2) {
          that.setData({
            scrollViewH: res1.windowHeight - res2[0].height
          })
          
        });
        
      }
    });
    HttpRequst(false, API.teamList, 1, app.getUkey(), { page: this.data.page, pagesize: this.data.pagesize, state: this.data.state}, "POST", false, function (res) {
     
      that.setData({
        info:res.data,
        isLoading:false,
        page:that.data.page+1,
        isEnding: (res.data.list.length < that.data.pagesize) ? true :false
      })
    })

  },
 
  lower:function(){
    if (this.data.isEnding || this.data.isLoading) return;
    var that=this;
    this.setData({
      isLoading: true
    });
    HttpRequst(false, API.teamList, 1, app.getUkey(), { page: this.data.page, pagesize: this.data.pagesize, state: this.data.state }, "POST", false, function (res) {
      that.setData({
        ["info.list"]: that.data.info.list.concat(res.data.list),
        isLoading: false,
        page: that.data.page + 1,
        isEnding: (res.data.list.length < that.data.pagesize) ? true : false
      });
    })
  },
  navLevelHandler:function(e){
    //e.currentTarget.dataset.level
    if (e.currentTarget.dataset.state == this.data.state) return;
    var that=this;
    this.setData({
      page: 1,
      scrollTop:0,
      state: e.currentTarget.dataset.state,
      isLoading: true,
      isEnding: false,
      ["info.list"]:[]
    })
    HttpRequst(false, API.teamList, 1, app.getUkey(), { page: this.data.page, pagesize: this.data.pagesize, state: this.data.state }, "POST", false, function (res) {
      that.setData({
        ["info.list"]: that.data.info.list.concat(res.data.list),
        isLoading: false,
        page: that.data.page + 1,
        isEnding: (res.data.list.length < that.data.pagesize) ? true : false
      });
    })

  }
})